package com.ruoyi.course.domain;

import java.util.Date;

import com.doudou.core.lang.Option;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import javax.validation.constraints.NotNull;

/**
 * course_record对象 course_study_record
 *
 * @author zzx
 * @date 2023-04-05
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@ToString
public class CourseStudyRecord extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;

    /**
     * 用户编号
     */
    private Long userId;
    private String userName;

    /**
     * 机构编号
     */
    private Long deptId;

    /**
     * 课程编号
     */
    @Excel(name = "课程编号")
    @NotNull(message = "课程编号不可为空")
    private Long trainId;
    private CourseTrain train;
    @NotNull(message = "课件编号不可为空")
    private Long wareId;
    private Integer wareTotal;

    /**
     * 已学习总数
     */
    @Excel(name = "已学习总数")
    private Integer studyTotal;

    /**
     * 已学习课件id集合
     */
    private String studyList;

    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date endTime;

    /**
     * 状态
     */
    @Excel(name = "状态")
    private Integer status;

    /**
     * 预留字段1
     */
    private String reservedOne;

    /**
     * 预留字段2
     */
    private String reservedTwo;

    /**
     * 正确率
     */
    private Double accuracyNumber = 0D;
    private String accuracy = "0%";

    public void addAccuracy(Double accuracy) {
        this.accuracyNumber += accuracy;
    }

    public void setAccuracyNumber(Double accuracy){
        this.accuracyNumber = accuracy;
        this.accuracy = this.accuracyNumber + "%";
    }

    public Integer resetStudyTotal() {
        Integer total = Option.of(this.studyTotal).get(0);
        if (total > this.wareTotal){
            this.studyTotal = this.wareTotal;
            return this.studyTotal;
        }
        return null;
    }
}
